var t = getApp();

Page({
    data: {
        userInfo: "",
        pic: "../../images/22.png",
        canIu: !0,
        condition: !0,
        sharecond: !0,
        auth: !0,
        inputpage: !0,
        longterm: !0,
        totalsum: "",
        img1: "../../images/23.png",
        img2: "../../images/24.png",
        img3: "../../images/25.png",
        img4: "../../images/22.png",
        img5: "../../images/26.png",
        hetongData:{}
    },
    onLoad: function() {
      var that =this;
      wx.request({
        url: "http://127.0.0.1:8082/wx/user/index",
        data: {
          // code: res.code,
          // userInfo: e.detail.userInfo
        },
        method: "GET",
        header: {
          'Content-Type': 'application/json; charset=UTF-8',
          'X-Litemall-Token': wx.getStorageSync('token')
        },
        success: function (res) {
          // resolve(res);
          // wx.setStorageSync('userId', res.data.data.userId);
          // wx.setStorageSync('token', res.data.data.token);
          that.setData({
            hetongData:res.data.data.order
          });

        },
      })
        !0 !== wx.canIUse("open-data.type.userAvatarUrl") && this.setData({
            canIu: !1
        });
        var o = wx.getStorageSync("userInfo");
        o ? this.setData({
            userInfo: o
        }) : this.setData({
            "userInfo.avatarUrl": "../../images/18.png",
            "userInfo.nickName": "我的昵称"
        }), t.globalData.PHPSESSID ? this.sessValid() : t.WxLogin();
    },
    onReady: function() {},
    MyDraft: function() {
        wx.navigateTo({
            url: "../MyCenter/MyCenter?Listurl=Smcontract/Smcontract/&TopName=我起草的合同"
        });
    },
    WtDraft: function() {
        wx.navigateTo({
            url: "../MyCenter/MyCenter?Listurl=Wdraft/Wdraft/&TopName=委托起草的合同"
        });
    },
    WtExam: function() {
        wx.navigateTo({
            url: "../MyCenter/MyCenter?Listurl=Examhtong/Examhtong/&TopName=委托审查的合同"
        });
    },
    Invoice: function() {
        wx.navigateTo({
            url: "../MyAsk/MyAsk?Listurl=Askplat/Askplat/&TopName=我咨询过的问题"
        });
    },
    contactus: function() {
        wx.navigateTo({
            url: "../InvoiceCter/InvoiceCter"
        });
    },
    toAsk: function() {
        wx.redirectTo({
            url: "../Ask/Ask"
        });
    },
    toReglist: function() {
        wx.redirectTo({
            url: "../reglist/reglist"
        });
    },
    sessValid: function() {
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/sessValid",
            data: {},
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(o) {
                console.log(o.data), 0 == o.data && t.WxLogin();
            },
            fail: function(o) {
                t.WxLogin();
            }
        });
    },
    getAuth: function() {
        var o = this;
        wx.openSetting ? wx.openSetting({
            success: function(e) {
                console.log(e), 1 == e.authSetting["scope.userInfo"] && t.getUserInfo(function(e) {
                    e ? (o.setData({
                        userInfo: e
                    }), wx.request({
                        url: t.url + "addon/Loginlog/Loginlog/Saveloginame",
                        data: {
                            nickName: e.nickName,
                            city: e.city,
                            province: e.province,
                            gender: e.gender,
                            avatarUrl: e.avatarUrl
                        },
                        method: "POST",
                        header: {
                            "content-type": "application/x-www-form-urlencoded",
                            Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                        },
                        success: function(t) {
                            console.log(t);
                        },
                        fail: function(t) {}
                    })) : o.setData({
                        "userInfo.avatarUrl": "../../images/18.png"
                    });
                });
            }
        }) : wx.showModal({
            title: "提示",
            content: "当前微信版本过低，无法获取头像授权，请升级到最新微信版本后重试。",
            showCancel: !1
        });
    },
    bindgetuserinfo: function(o) {
        if (console.log(o), "getUserInfo:ok" == o.detail.errMsg) {
            this.setData({
                userInfo: o.detail.userInfo,
                auth: !0
            });
            var e = o.detail.userInfo, a = wx.getStorageSync("userInfo");
            e.nickName !== a.nickName && wx.request({
                url: t.url + "addon/Loginlog/Loginlog/Saveloginame",
                data: {
                    nickName: e.nickName,
                    city: e.city,
                    province: e.province,
                    gender: e.gender,
                    avatarUrl: e.avatarUrl
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {},
                fail: function(t) {}
            }), wx.setStorageSync("userInfo", e);
        }
    },
    closepage: function(t) {
        this.setData({
            condition: !0
        });
    },
    myHTbi: function(o) {
        wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 25e3
        });
        var e = this;
        wx.request({
            url: t.url + "addon/Loginlog/Loginlog/gethtbi",
            data: {},
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                wx.hideToast(), console.log("有：", t), e.setData({
                    totalsum: t.data,
                    condition: !1
                });
            },
            fail: function(t) {
                wx.hideToast(), wx.showToast({
                    title: "网络连接异常",
                    icon: "loading",
                    duration: 2e3
                });
            }
        });
    },
    longtermReg: function(o) {
        wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 25e3
        });
        var e = this;
        o.detail.value.Cusphone ? wx.request({
            url: t.url + "addon/Longtermreg/Longtermreg/regLong",
            data: {
                Cusname: o.detail.value.Cusname,
                Cusphone: o.detail.value.Cusphone,
                Cusman: o.detail.value.Cusman
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                wx.hideToast(), console.log("有：", t), wx.showToast({
                    title: "提交成功",
                    icon: "loading",
                    duration: 2500
                }), e.setData({
                    longterm: !0
                });
            },
            fail: function(t) {
                wx.hideToast(), wx.showToast({
                    title: "网络连接异常",
                    icon: "loading",
                    duration: 2500
                });
            }
        }) : wx.showToast({
            title: "信息填写不完整",
            icon: "loading",
            duration: 2500
        });
    },
  weihetong: function () {
    console.log("qwe");
    wx: wx.navigateTo({
      url: 'weiwancheng/weiwancheng',
    })
  },
  hetong: function () {
    wx: wx.navigateTo({
      url: 'myhetong/myhetong',
    })
  },
  share: function () {
    wx: wx.navigateTo({
      url: 'sharehetong/sharehetong',
    })
  },
    toinputsumpage: function(t) {
        this.setData({
            inputpage: !this.data.inputpage
        });
    },
    bindsuminput: function(t) {
        this.setData({
            sharesum: t.detail.value
        });
    },
    Delplace: function(t) {
        return t.replace(/(^\s*)|(\s*$)/g, "");
    },
    isPositiv: function(t) {
        return /^\+?[1-9][0-9]*$/.test(t);
    },
    isarab: function(t) {
        return /^[0-9]+.?[0-9]*/.test(t);
    },
    Tolongterm: function(t) {
        this.setData({
            longterm: !1
        });
    },
    Esclongterm: function(t) {
        this.setData({
            longterm: !0
        });
    },
    NOTonShareAppMessage: function(o) {
        if (this.setData({
            sharecond: !1
        }), "button" === o.from) {
            console.log(o.target);
            var e = this.data.totalsum, a = wx.getStorageSync("PHPSESSID") + "||" + new Date().valueOf(), n = wx.getStorageSync("userInfo");
            if (n.nickName) s = n.nickName; else var s = "";
            var i = this.data.sharesum, c = this.Delplace(i);
            console.log(a);
            var l = this.isPositiv(c);
            if (console.log(l), 1 == l && e >= c) {
                console.log("数字判断：", l);
                var r = this;
                return {
                    title: "你的好友" + s + "向你赠送了" + c + "合同币",
                    path: "/pages/MyCover/MyCover?sharecard=" + a + "&sharesum=" + c,
                    imageUrl: "../../images/07.jpg",
                    success: function(o) {
                        wx.showToast({
                            title: "数据加载",
                            icon: "loading",
                            duration: 2e4
                        }), wx.request({
                            url: t.url + "addon/Sharecard/Sharecard/addCard",
                            data: {
                                sharecard: a,
                                sharesum: c
                            },
                            method: "POST",
                            header: {
                                "content-type": "application/x-www-form-urlencoded",
                                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                            },
                            success: function(t) {
                                wx.hideToast(), console.log(t.data), t.data >= 0 ? (r.setData({
                                    totalsum: t.data
                                }), r.toinputsumpage(), wx.showModal({
                                    title: "提示",
                                    content: "赠送成功，你当前剩余" + t.data + "合同币",
                                    showCancel: !1,
                                    success: function(t) {
                                        t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                                    }
                                })) : (wx.hideToast(), wx.showModal({
                                    title: "提示",
                                    content: "你的合同币余额不足，请调整赠送金额。",
                                    showCancel: !1,
                                    success: function(t) {
                                        t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                                    }
                                }));
                            },
                            fail: function(t) {}
                        });
                    },
                    fail: function(t) {},
                    complete: function(t) {}
                };
            }
            if (console.log("不是合格数字"), e < c) u = "你的合同币余额不足，请调整赠送金额。"; else var u = "你输入的赠送金额不是阿拉伯数字，赠送没有成功，请输入阿拉伯数字。";
            return {
                title: "你的好友正在使用合同起草助手小程序",
                path: "/pages/Draft/Draft",
                imageUrl: "../../images/08.jpg",
                success: function(t) {
                    wx.showModal({
                        title: "提示",
                        content: u,
                        confirmText: "确定",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm;
                        }
                    });
                }
            };
        }
        return {
            title: "合同起草助手",
            path: "/pages/MyCover/MyCover",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        };
    },
    lastonLoad: function(o) {
        var e = t.globalData.PHPSESSID, a = wx.getStorageSync("userInfo");
        if (a ? this.setData({
            userInfo: a
        }) : this.setData({
            "userInfo.avatarUrl": "../../images/18.png",
            "userInfo.nickName": "我的昵称"
        }), o.sharecard) if (this.setData({
            condition: !1
        }), console.log("sharecard：", o), wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        }), e) {
            wx.request({
                url: t.url + "addon/Sharecard/Sharecard/Cardraw",
                data: {
                    sharecard: o.sharecard
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    wx.hideToast(), "getok" == t.data.ids ? (n.setData({
                        totalsum: t.data.sums
                    }), wx.showModal({
                        title: "提示",
                        content: "恭喜你领取到" + o.sharesum + "合同币",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                        }
                    }), console.log("有的：", t)) : ("nosum" == t.data.ids ? (n.setData({
                        totalsum: t.data.sums
                    }), wx.showModal({
                        title: "提示",
                        content: "该赠券已经被领取过了",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                        }
                    })) : (n.setData({
                        totalsum: t.data.sums
                    }), wx.showModal({
                        title: "提示",
                        content: "该赠券是你赠出的，自己送出的东西，不能自己收回的",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                        }
                    })), console.log("无的：", t));
                },
                fail: function(t) {}
            });
            n = this;
            a || wx.request({
                url: t.url + "addon/Loginlog/Loginlog/infotest",
                data: {},
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    console.log(t), 1 !== t.data && n.setData({
                        auth: !1
                    });
                },
                fail: function(t) {}
            });
        } else {
            n = this;
            t.getWxLogin(function(e) {
                console.log(e), wx.request({
                    url: t.url + "addon/Sharecard/Sharecard/Cardraw",
                    data: {
                        sharecard: o.sharecard
                    },
                    method: "POST",
                    header: {
                        "content-type": "application/x-www-form-urlencoded",
                        Cookie: "PHPSESSID=" + e
                    },
                    success: function(t) {
                        wx.hideToast(), "getok" == t.data.ids ? (n.setData({
                            totalsum: t.data.sums
                        }), wx.showModal({
                            title: "提示",
                            content: "恭喜你领取到" + o.sharesum + "合同币",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                            }
                        })) : "nosum" == t.data.ids ? (n.setData({
                            totalsum: t.data.sums
                        }), wx.showModal({
                            title: "提示",
                            content: "该赠券已经被领取过了",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                            }
                        })) : (n.setData({
                            totalsum: t.data.sums
                        }), wx.showModal({
                            title: "提示",
                            content: "该赠券是你赠出的，自己送出的东西，不能自己收回的",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                            }
                        })), console.log("无:", t);
                    },
                    fail: function(t) {
                        wx.hideToast();
                    }
                }), a || wx.request({
                    url: t.url + "addon/Loginlog/Loginlog/infotest",
                    data: {},
                    method: "POST",
                    header: {
                        "content-type": "application/x-www-form-urlencoded",
                        Cookie: "PHPSESSID=" + e
                    },
                    success: function(t) {
                        console.log(t), 1 !== t.data && n.setData({
                            auth: !1
                        });
                    },
                    fail: function(t) {}
                });
            });
        } else if (e) {
            n = this;
            a || wx.request({
                url: t.url + "addon/Loginlog/Loginlog/infotest",
                data: {},
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    console.log("有：", t), 1 !== t.data && n.setData({
                        auth: !1
                    });
                },
                fail: function(t) {}
            });
        } else {
            var n = this;
            t.getWxLogin(function(o) {
                a || wx.request({
                    url: t.url + "addon/Loginlog/Loginlog/infotest",
                    data: {},
                    method: "POST",
                    header: {
                        "content-type": "application/x-www-form-urlencoded",
                        Cookie: "PHPSESSID=" + o
                    },
                    success: function(t) {
                        console.log("无：", t), 1 !== t.data && n.setData({
                            auth: !1
                        });
                    },
                    fail: function(t) {}
                });
            });
        }
    }
});